package cartao;

import br.edu.GenericDAO;
import org.hibernate.Session;
import org.hibernate.Transaction;
import br.edu.HibernateUtil;

public class CartaoDAO extends GenericDAO<Cartao> {

    private Session sessao;
    private Transaction transacao;
    
    public CartaoDAO() {
        super(Cartao.class);
    }
    
    public void salvar(Cartao cartao){
        sessao = HibernateUtil.getSessionFactory()
                .openSession();
        transacao = sessao.beginTransaction();
        if (cartao.getId_cartao() == 0){
            sessao.save(cartao);
        }else{
            sessao.update(cartao);
        }
        transacao.commit();
        sessao.close();
    }
    
    
    
    public void deletar(Cartao cartao){
        sessao = HibernateUtil.getSessionFactory()
                .openSession();
        transacao = sessao.beginTransaction();
        sessao.delete(cartao);
        transacao.commit();
        sessao.close();
    }
}